var express = require('express');
var router = express.Router();
var tokenDao = require('./tokenDao');
var historysDao = require('../dao/historys.dao');


// 增
router.post('/add', (req, res) => {

    var token = req.get('token');

    var userId = tokenDao.verify(token);

    if (!req.body) {
        res.json({ success: false, info_massage: '缺少参数' });
        return;
    }


    historysDao.add(req.body, userId, res);

});

// 删
router.post('/delete', (req, res) => {
    var token = req.get('token');

    var userId = tokenDao.verify(token);

    if (!req.body) {
        res.json({ success: false, info_massage: '缺少参数' });
        return;
    }


    historysDao.del(req.body, userId, res);


});

// 改
router.post('/update', (req, res) => {

    var token = req.get('token');

    var userId = tokenDao.verify(token);

    if (!req.body) {
        res.json({ success: false, info_massage: '缺少参数' });
        return;
    }

    historysDao.update(req.body, userId, res);

});

// 查
router.post('/find', (req, res) => {

    var token = req.get('token');

    var userId = tokenDao.verify(token);

    if (!req.body) {
        res.json({ success: false, info_massage: '缺少参数' });
        return;
    }    

    historysDao.search(req.body, userId, res);

});
// 分页
router.post('/page', (req, res) => {

    var token = req.get('token');

    var userId = tokenDao.verify(token);

    if (!req.body) {
        res.json({ success: false, info_massage: '缺少参数' });
        return;
    }    

    historysDao.page(req.body, userId, res);

});


module.exports = router;